package me.wangqu.weiyouqu.web.rest.business.dao.impl;

import me.wangqu.weiyouqu.web.rest.business.dao.VersionDao;
import me.wangqu.weiyouqu.web.rest.business.model.VersionModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by joln on 2016/7/30.
 */
@Repository
public class VersionImpl implements VersionDao {
    private Logger logger = LoggerFactory.getLogger(VideoImpl.class);
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public VersionModel getVersionData() {
        StringBuffer sql = new StringBuffer(128);
        sql.append("select v.id,v.version,v.desc,v.force_e,v.share from version v order by v.id desc limit 0,1");
        return jdbcTemplate.queryForObject(sql.toString(), new RowMapper<VersionModel>() {

            @Override
            public VersionModel mapRow(ResultSet rs, int rowNum) throws SQLException {
                VersionModel model = new VersionModel();
                model.setVersion(rs.getDouble("version"));
                model.setDesc(rs.getString("desc"));
                model.setForce(Boolean.valueOf(rs.getString("force_e")));
                model.setShare(rs.getInt("share"));

                return model;
            }
        });
    }
}
